import waflib.Task, waflib.TaskGen
from waflib.TaskGen import extension
from waflib.Options import options
from waf_dynamo import new_copy_task

new_copy_task('luascript', '.lua', '.luac')

def build(bld):
    if options.skip_build_tests:
       return
    libs = ['TESTMAIN', 'SCRIPT', 'EXTENSION', 'THREAD', 'RESOURCE', 'DDF', 'DLIB', 'PROFILE_NULL', 'LUA', 'GRAPHICS_NULL', 'PLATFORM_NULL']
    if 'android' in bld.env['PLATFORM']:
        libs.append('UNWIND')

    extra_features = []
    if bld.env['PLATFORM'] in ('x86_64-ps4', 'x86_64-ps5'):
        libs += ['SOCKET']
        extra_features = ['skip_test'] # until we've implemented a crash handler for PS4

    exported_symbols = ['CrashExt', 'ResourceProviderFile']

    test_crash = bld.program(features = 'cxx cprogram test'.split() + extra_features,
                             includes = '..',
                             use = libs + ['crashext'],
                             web_libs = ['library_sys.js'],
                             target = 'test_crash',
                             source = 'test_crash.cpp')

    test_crash.install_path = None
    if 'win32' in bld.env['PLATFORM']:
        test_crash.env.append_value('LINKFLAGS', ['Psapi.lib'])

    # essentially only test that it links
    test_crash_null = bld.program(features = 'cxx cprogram test skip_test',
                                     includes = '..',
                                     use = libs + ['crashext_null'],
                                     web_libs = ['library_sys.js'],
                                     target = 'test_crash_null',
                                     source = 'test_crash.cpp')

    test_crash_null.install_path = None

    test_script_crash = bld.program(features = 'cxx cprogram test'.split() + extra_features,
                                     includes = '..',
                                     use = libs + ['crashext'],
                                     web_libs = ['library_sys.js','library_script.js'],
                                     target = 'test_script_crash',
                                     exported_symbols = exported_symbols,
                                     source = 'test_script_crash.cpp test_crash.lua')

    if 'win32' in bld.env['PLATFORM']:
        test_script_crash.env.append_value('LINKFLAGS', ['Psapi.lib'])

    bld.program(features         = 'cxx cprogram test'.split() + extra_features,
                 includes         = '..',
                 use              = libs + ['crashext_null'],
                 web_libs         = ['library_sys.js','library_script.js'],
                 target           = 'test_script_crash_null',
                 exported_symbols = exported_symbols,
                 source           = 'test_script_crash_null.cpp test_crash_null.lua')
